/*
** my.h for mysh in /home/nadali_t//local/svn/tek2ed/minishell1
** 
** Made by thomas nadalie
** Login   <nadali_t@epitech.net>
** 
** Started on  Thu Nov  8 12:23:22 2012 thomas nadalie
** Last update Thu Nov  8 12:24:34 2012 thomas nadalie
*/

#ifndef		__MY_H__
#define		__MY_H__

#include	<sys/types.h>
#include	<sys/wait.h>
#include	<stdio.h>
#include	<strings.h>
#include	<stdarg.h>

typedef struct	s_list
{
  int		stop;
  int		end;
}		t_list;

typedef struct s_redir
{
  int		right;
  int		dright;
  int		left;
  int		dleft;
}		t_redir;

/* LIB */

# define        DECI    "0123456789"
# define        OCTAL   "01234567"
# define        HEXA    "0123456789ABCDEF"
# define        BIN     "01"

void		my_putchar(char c);
void		my_put_error(char *str);
void		my_put_nbr(int nb);
void		my_swap(int *a, int *b);
void		my_putstr(const char *str);
void		my_sort_int_tab(int *tab, int size);
void            my_bzero(char *b, size_t size);
void            my_showlist(char **tab);

int		my_isneg(int nb);
int		my_strlen(const char *str);
int		my_getnbr(char *str);
int		my_power_rec(int nb, int power);
int		my_square_root(int nb);
int		my_is_prime(int nombre);
int		my_find_prime_sup(int nb);
int		my_strcmp(char *s1, char *s2);
int		my_strncmp(char *s1, char *s2, int nb);
int		my_str_isalpha(char *str);
int		my_str_isnum(char *str);
int		my_str_islower(char *str);
int		my_str_isupper(char *str);
int		my_str_isprintable(char *str);
int		my_showstr(char *str);
int		my_showmem(char *str, int size);
int             my_strcpr(char *str, char *str2);
int		my_strlcat(char *dest, char *src, int size);

char		*my_strcpy(char *dest, char *src);
char		*my_strncpy(char *dest, char *src, int nb);
char		*my_revstr(char *str);
char		*my_strstr(char *str, char *to_find);
char		*my_strupcase(char *str);
char		*my_strlowcase(char *str);
char		*my_strcapitalize(char *str);
char		*my_strcat(char *dest, char *src);
char		*my_strncat(char *dest, char *src, int nb);
char            *my_strdup(const char *src);
char            *my_concat(char *str, char *str2);
char		*epur_str(char *str);

int             check_flag(char format, va_list ap);
int             catch_opt(const char *format, va_list ap);
char            *convert_func(int nb, char *base, int i, int count2);
char            *convert_base(char *nbr, char *base_from, char *base_to);
void            init_functab(void (**functab)(va_list));
void            init_flagtab(char *tab);
int             my_printf(const char *format, ...);
void            opt_xx();
void            opt_b(va_list ap);
void            opt_d(va_list ap);
void            opt_i(va_list ap);
void            opt_o(va_list ap);
void            opt_u(va_list ap);
void            opt_x();
void            opt_s(va_list ap);
void            opt_c(va_list ap);
void            opt_percent();

/* XFUNC */

void		*xmalloc(int size);
pid_t		xwait(int *statut);
pid_t		xfork();
int		xopen(char *pathname, int flag);
int		xdup2(int oldfd, int newfd);

/* SHELL */

char		**make_read(char **env);
char		**make_env(char **env);
int             my_wordlen(char *str, int i);
int             count_word(char *str);
char            *copy_word(char *str, int i);
char            **my_str_to_wordtab(char *str);
int             my_pathlen(char *str, int i);
int             count_path(char *str);
char            *copy_path(char *str, int i);
char            **my_path_to_wordtab(char *str);
char		**exec_cmd(char **path, char **tab, char **env);
char		**exec_cmd2(char **path, char **tab, char **env, t_list *list);
void		aff_prompt();
char		**get_path(char **env);
char		*make_path(char *env);
int		find_path(char *s1, char *s2);
char		**concat_path(char **path, char *cmd);
int		my_tablen(char **tab);
char		**my_env(char **env);
char		**catch_builtins(char **cmd, char **env, t_list *list);
char		**my_setenv(char **env, char *param, t_list *list);
char		**clean_env(char **env, int i);
char		**my_unsetenv(char **env, char *param, t_list *list);
void		my_put_error(char *str);
int		my_bcmp(char *str, char *str2);
int		epur_buff(char *buff, int i);
void		my_exit(char *cmd, t_list *list);
void		init_struct(t_list *list);
void		cmd_error(char **tab);
void		catch_ctrl(int sign);
char		**check_cmd(char **cmd, char **env);
char		**my_bin(char *str, char **env, t_list *list);
char		**exec_bin(char *str, char **tab, char **env);
int		str_isoption(char *str);
char		*epur_it(char *str);
char		**redir_right(int fd, char **cmd, t_redir *redir);
int		d_right(char **cmd, int oldfd);
int		s_right(char **cmd, int oldfd);
char		**find_redir(char **cmd, t_redir *redir);
int		check_redir(char **cmd, t_redir *redir);
int		check_nb_redir(t_redir *redir);

int		value_prompt;

#endif
